package com.lanou.myapp.news.recommendednews.contentrecommendednews;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.myapp.R;
import com.lanou.myapp.imageloader.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/20.
 */
public class PictureViewPagerAdapter extends PagerAdapter{
    private List<PictureBeans.DataEntity.ItemsEntity> data;
    private Context context;
    private TextView tv_num, tv_num2, tv_title;
    private ImageView imageView;

    public PictureViewPagerAdapter(Context context) {
        data = new ArrayList<>();
        this.context = context;
    }


    public void addData(List<PictureBeans.DataEntity.ItemsEntity> data){
        this.data = data;
        Log.d("dfafdg",data.size()+ "");
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return data.size() > 0 && data != null ? data.size() : 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_view_pager,null);
        tv_num = (TextView) view.findViewById(R.id.tv_num_item_viewPager);
        tv_num2 = (TextView) view.findViewById(R.id.tv_num2_item_viewPager);
        tv_title = (TextView) view.findViewById(R.id.tv_item_viewPager);
        imageView = (ImageView) view.findViewById(R.id.iv_item_viewPager);

        tv_num.setText(String.valueOf(position + 1));
        tv_num2.setText(String.valueOf(data.size()));
        tv_title.setText(data.get(position).getDesc());
        Log.d("dsfsadfd", data.get(position).getDesc());
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView, R.mipmap.v6_boy_unseletor_icon, R.mipmap.v6_boy_unseletor_icon);
        VolleySingleton.getImageLoader().get(data.get(position).getImg(), listener);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

    }
}
